home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / BTRVEX.ZIP / BTRVEXPR.DOC < prev    next >
Encoding:
Text File  |  1989-08-07  |  60.3 KB  |  1,832 lines

  1. The BTRV Express library manages the task of finding and opening Btrieve 
  2. files.  On the first call to any file, whether it is to retrieve a record or to 
  3. find out how many records are in the file, the library will automatically 
  4. allocate a position block and make sure that the correct position block is used 
  5. in all subsequent calls to the file.
  6.  
  7. In addition to the position block, the library will keep track of the memory 
  8. location of the last record buffer used, the record length, the last index 
  9. number used to access the file, and the length of each key definition.  All of 
  10. this information is updated each time you access a file.  
  11.  
  12. All references to a file are by file name.  For instance, to get a record for 
  13. Ed Edwards from a file named EMPLOYEE.DAT and read it into a buffer named 
  14. EMP_BUF, the call would look like this:
  15.  
  16.        status = BGET(B_EQ,"EMPLOYEE.DAT",0,EMP_BUF,"ED EDWARDS")
  17.  
  18. Even if this is the first call to the employee file in your program, the record 
  19. will be retrieved.  You never have to explicitly OPEN the file.  The library 
  20. routines will find your file if it is in the DOS search path.  These routines 
  21. also free you from hard coding the record lengths of your data files.  Just 
  22. change the structure definition of the record buffer in your application and 
  23. the library will automatically adapt to the new record length by inspecting the 
  24. data file.  
  25.  
  26. All calls to Btrieve are made through a central module.  The advantage of this 
  27. is that you can modify that module to perform a certain function each time a 
  28. file is accessed.  This feature could be most  most useful in a network 
  29. environment.  For instance, you can place a routine in the central module that 
  30. checks for hardware errors on the server and logs the user off gently if there 
  31. is trouble.   
  32.  
  33. Most errors are handled automatically, which will drastically reduce the amount 
  34. of error handling code you need to write.  If a file is not found when a record 
  35. is requested, an error message will display and the program will exit to DOS.  
  36. Usually, the control will only be passed back to your program if the call is 
  37. successful.  Under some circumstances, you will still need error handling 
  38. code.  One example is record searching.  If a record is not found (but the 
  39. filename is valid), a return code will give the status of the search.  Another 
  40. example is adding a record.  If a duplicate record is added on a key defined as 
  41. not allowing duplicates, an error code will be returned to your application.
  42.  
  43. Requirements
  44.  
  45. This library was designed for Microsoft C version 5.0 and above, Btrieve 
  46. version 4.10, an IBM PC, AT, PS/2 or 100% compatible.  It is intended for use 
  47. with a hard disk but this is not required.  A version for Turbo C v2.0 is 
  48. planned.  Also in the works is a Norton Guide reference file.
  49. Page 2                                                                  BTRV Express
  50.                                                                                     
  51.  
  52. How It Works
  53.  
  54. Before making any other library call, one of the first statements in your 
  55. application must be a call to BSTART().  This module does two things: it makes 
  56. sure that the Btrieve record manager is loaded in memory and locates the 
  57. BTRERROR.DAT file which stores the library's error messages.  If either Btrieve 
  58. is not loaded or BTRERROR.DAT cannot be found, the program will exit to DOS.  
  59. If control is returned to your application, then you may make library calls as 
  60. usual.  The BSTART() module will also load the current version of Btrieve in a 
  61. global variable named BTR_VERSION.    
  62.  
  63. A global array named BTR_FILES holds the definitions for open files.  It is 
  64. maintained by the central calling module BXTR.  Each time a request comes 
  65. through BXTR, the filename is searched for in BTR_FILES.  If the file name is 
  66. found, the library will supply all of the needed information to make the 
  67. Btrieve call.  If the file name is not found, a new position block is allocated 
  68. and the file is opened, after which the file's structure and related 
  69. information (record buffer, index number, record length, etc.) are entered into 
  70. the array.  The call to Btrieve is then processed.
  71.  
  72. An invalid filename will always cause the library to display a message and exit 
  73. to DOS.  This error will be caught and processed in the BXTR module.  Other 
  74. errors are caught in the individual routines that handle special calls and 
  75. cases.  These are documented in the function call reference and in the source 
  76. code.
  77.  
  78. After a call involving record retrieval, addition, or update, the 'keytemp' 
  79. character buffer contains the key value for the record.  For example, if you 
  80. add a record to an employee file that is indexed on employee number, the 
  81. 'keytemp' buffer will contain the employee number.  This buffer is quite handy 
  82. for GET KEY ONLY operations (see Btrieve manual for a better explanation).
  83.  
  84. The 'keytemp' buffer is used mainly as a holding area for search criteria.  If 
  85. you were to search a file for a certain employee number, the number would be 
  86. copied to 'keytemp'.  The address of 'keytemp' is passed to Btrieve so that the 
  87. returned key can be placed in the buffer and the original key value is 
  88. preserved.
  89.  
  90. The 'keytemp' buffer can also be loaded directly by your application for use in 
  91. GET operations but remember that its value is not guaranteed to be the same 
  92. upon return from the call.  If it is important to retain the original value, 
  93. then pass the key in your own separate buffer.
  94.  
  95.  
  96. Page 3                                                                  BTRV Express
  97.                                                                                     
  98.  
  99. Using the Library in Your Application
  100.  
  101. The source code is written for Microsoft C v5.0.  Include the following line at 
  102. the top of your application: 
  103.  
  104.                               #include <BTRVEXP.H>
  105.  
  106. Compile your application (the /Zp switch is recommended) and link it with the 
  107. correct model version of BTRV Express:
  108.  
  109.      BTRVEXPS.OBJ - Small Model    BTRVEXPC.OBJ - Compact Model
  110.      BTRVEXPM.OBJ - Medium Model   BTRVEXPL.OBJ - Large Model  
  111.  
  112.  
  113.  
  114. Global Variables
  115.  
  116. int BSTATUS:
  117.        Always holds the status value of the last Btrieve call.
  118.  
  119. int open_files:
  120.        Number of currently open Btrieve files.
  121.  
  122. struct BTR_FILES btr_files[MAX_BTR_FILES]
  123.        Main array which holds position blocks and support information for file 
  124.        management.  This array is manipulated by the BXTR routine.
  125.        
  126.        struct {
  127.           char *filename;
  128.           char *pos_blk;
  129.           char *last_rec_buf;
  130.           char *ndx_lens;
  131.           int   numindexes;
  132.           int   rec_len;
  133.           int   last_index;
  134.           } btr_files[MAX_BTR_FILES];
  135.          
  136.         
  137.        filename    :  name of file (filename and extension only).
  138.        pos_blk     :  allocated 128 byte position block.
  139.        last_rec_buf:  address of last record buffer used on this file.
  140.        ndx_lens    :  pointer to integer array of index lengths (one value for 
  141.                       each index).
  142.        numindexes  :  number of indexes (number of elements in ndx_lens).
  143.        rec_len     :  record length.
  144.        last_index  :  last index number used to access a record.
  145.  
  146. char keytemp[255]:
  147.        Temporary buffer for working with key values.  After a BGET call, it 
  148.        will hold the key value of record retrieved.  Since a key definition 
  149.        cannot be longer than 255 bytes, keytemp will hold any value.
  150.  
  151. Page 4                                                                  BTRV Express
  152.                                                                                     
  153.  
  154. struct BTR_VERSION btr_version:
  155.        Holds version of Btrieve being used.  See documentation for  function 
  156.        BSTART() for structure.
  157.  
  158. struct STATBUF global_statbuf:
  159.        Global status buffer used when calling BFILEINFO.  The status buffer is 
  160.        large enough to hold any file definition containing the maximum of 24 
  161.        key segment definitions and an alternate collating sequence.  If you use 
  162.        this buffer to create your own files and want to load an alternate 
  163.        collating sequence, remember that the definition for the collating 
  164.        sequence must immediately follow your last key segment definition.  The 
  165.        Alternate Collating Sequence will usually not be placed in 
  166.        'global_statbuf.altcolseq'.  The slot is there just to reserve enough 
  167.        space for the longest possible definition.  The length of the file 
  168.        definition is passed back and forth through 'global_statbuf.buf_len'.
  169.  
  170. struct ERROR_MSG errmsg:
  171.        The records in the file BTRERROR.DAT correspond to the Btrieve error 
  172.        codes.  When a library function returns a status other than 0, you can 
  173.        call GET_ERR_MSG with the status number.  The error message is returned 
  174.        in the global variable 'errmsg'.  For the structure and an example of 
  175.        its use, see the explanation of the GET_ERR_MSG function call.
  176.  
  177. int CATCH_ERROR;
  178.        CATCH_ERROR is initialized to TRUE.  When TRUE, fatal errors that are 
  179.        caught by the library will cause an error message to display at the 
  180.        bottom of the screen and an exit to DOS.  If you wish to have your own 
  181.        error handling system, initialize this variable to FALSE and all errors 
  182.        will be returned to your program in the status code (BSTATUS).
  183.  
  184. int RETURN_KEY_BUFFER
  185.        When TRUE, a call made to  retrieve a record returns the key value in 
  186.        your defined key buffer.  This means, for example, that to search for an 
  187.        employee by a partial name, you must pass a key buffer long enough to 
  188.        hold the entire name.  
  189.        
  190.        This is not always convenient.  For that reason, a temporary buffer (see 
  191.        'keytemp' above) has been reserved to catch the key value of any record 
  192.        when it is retrieved.  The RETURN_KEY_BUFFER variable is initialized to 
  193.        FALSE.  The key buffer you pass down will remain unaltered unless you 
  194.        change the value of RETURN_KEY_BUFFER to TRUE.  Btrieve will then return 
  195.        the key value both in your key buffer and in 'keytemp'.  You can set the 
  196.        value of RETURN_KEY_BUFFER at any time in your application.
  197.  
  198. int DEL_POSITION
  199.        Positiong the data file after a DELETE poses a special problem.  Under 
  200.        normal circumstances, the data file is at an invalid position after a 
  201.        DELETE.  This means that many of the library functions will not work if 
  202.        called directly after a deletion.  The external variable DEL_POSITION 
  203.        tells the library what to do after a record deletion.  If TRUE (the 
  204.        default setting), then the library will place the data file at the 
  205.        record directly after the deleted one using the current index number.  
  206.        If you have just deleted the highest record in the index, the file will 
  207.        be positioned at the next highest record.  You 
  208. Page 5                                                                  BTRV Express
  209.                                                                                     
  210.  
  211.        should note that the act of positioning the file will alter the contents 
  212.        of that file's record buffer even though you do not pass the buffer as a 
  213.        parameter to BDELETE.  
  214.        
  215.        If DEL_POSITION is FALSE, then only the deletion happens during a 
  216.        BDELETE call and the file is not positioned afterward.  It is up to your 
  217.        application to determine the next correct position.
  218.  
  219.  
  220. Note: keytemp, global_statbuf and charbuf are used by the library as temporary 
  221. holding areas for various items.  They are not guaranteed to retain values 
  222. across calls.
  223.  
  224.  
  225. Defined Constants
  226.  
  227. #define TRUE          1
  228. #define FALSE         0
  229. #define ALL_FILES     NULL ; See BCLOSE for usage
  230. #define B_LOCK_WAIT   100  ; See BGET for usage
  231. #define B_LOCK_NOWAIT 200  ; See BGET for usage
  232. #define B_OPEN        0
  233. #define B_CLOSE       1
  234. #define B_INSERT      2
  235. #define B_UPDATE      3
  236. #define B_DELETE      4
  237. #define B_EQ          5    ; Get Equal
  238. #define B_NEXT        6    ; Get Next
  239. #define B_PREV        7    ; Get Previous
  240. #define B_GT          8    ; Get Greater Than
  241. #define B_GE          9    ; Get Greater Than or Equal to
  242. #define B_LT         10    ; Get Less Than
  243. #define B_LE         11    ; Get Less Than or Equal to
  244. #define B_LOW        12    ; Get Lowest
  245. #define B_HIGH       13    ; Get Highest
  246. #define B_CREATE     14
  247. #define B_STAT       15
  248. #define B_EXTEND     16
  249. #define B_SETDIR     17
  250. #define B_GETDIR     18
  251. #define B_BEGTRANS   19
  252. #define B_ENDTRANS   20
  253. #define B_ABORTTRANS 21
  254. #define B_GETPOS     22
  255. #define B_GETDIRECT  23
  256. #define B_STEP       24
  257. #define B_STOP       25
  258. #define B_VERSION    26
  259. #define B_UNLOCK     27
  260. #define B_RESET      28
  261. #define B_SETOWNER   29
  262. #define B_CLEAROWNER 30
  263. #define B_EQ_KEY     55    ; Key only operation 
  264. #define B_NEXT_KEY   56    ; Key only operation   
  265. Page 6                                                                  BTRV Express
  266.                                                                                     
  267.  
  268. #define B_PREV_KEY   57    ; Key only operation   
  269. #define B_GT_KEY     58    ; Key only operation   
  270. #define B_GE_KEY     59    ; Key only operation   
  271. #define B_LT_KEY     60    ; Key only operation   
  272. #define B_LE_KEY     61    ; Key only operation   
  273. #define B_LOW_KEY    62    ; Key only operation   
  274. #define B_HIGH_KEY   63    ; Key only operation   
  275.  
  276. And if you like to use lower case:
  277.  
  278. #define b_open       B_OPEN
  279. #define b_close      B_CLOSE
  280. #define b_insert     B_INSERT
  281. #define b_update     B_UPDATE
  282. #define b_delete     B_DELETE
  283. #define b_eq         B_EQ
  284. #define b_next       B_NEXT
  285. #define b_prev       B_PREV
  286. #define b_gt         B_GT
  287. #define b_ge         B_GE
  288. #define b_lt         B_LT
  289. #define b_le         B_LE
  290. #define b_low        B_LOW
  291. #define b_high       B_HIGH
  292. #define b_create     B_CREATE
  293. #define b_stat       B_STAT
  294. #define b_extend     B_EXTEND
  295. #define b_setdir     B_SETDIR
  296. #define b_getdir     B_GETDIR
  297. #define b_begtrans   B_BEGTRANS
  298. #define b_endtrans   B_ENDTRANS
  299. #define b_aborttrans B_ABORTTRANS
  300. #define b_getpos     B_GETPOS
  301. #define b_getdirect  B_GETDIRECT
  302. #define b_step       B_STEP
  303. #define b_stop       B_STOP
  304. #define b_version    B_VERSION
  305. #define b_unlock     B_UNLOCK
  306. #define b_reset      B_RESET
  307. #define b_setowner   B_SETOWNER
  308. #define b_clearowner B_CLEAROWNER
  309. #define b_eq_key     B_EQ_KEY
  310. #define b_next_key   B_NEXT_KEY
  311. #define b_prev_key   B_PREV_KEY
  312. #define b_gt_key     B_GT_KEY
  313. #define b_ge_key     B_GE_KEY
  314. #define b_lt_key     B_LT_KEY
  315. #define b_le_key     B_LE_KEY
  316. #define b_low_key    B_LOW_KEY
  317. #define b_high_key   B_HIGH_KEY
  318.  
  319.  
  320. Page 7                                                                  BTRV Express
  321.                                                                                     
  322.  
  323. Error Return Codes
  324.  
  325. #define ERR_INVALOP       1
  326. #define ERR_IO            2
  327. #define ERR_NOOPEN        3
  328. #define ERR_KEYNOTFOUND   4
  329. #define ERR_DUPLICATE     5
  330. #define ERR_INVALKEYNUM   6
  331. #define ERR_DIFFKEYNUM    7
  332. #define ERR_INVALPOSITION 8
  333. #define ERR_EOF           9
  334. #define ERR_MODIFIABLE    10
  335. #define ERR_INVALFILENAME 11
  336. #define ERR_FILENOTFOUND  12
  337. #define ERR_EXTENSION     13
  338. #define ERR_PREOPEN       14
  339. #define ERR_PREIMAGE      15
  340. #define ERR_EXPANSION     16
  341. #define ERR_CLOSE         17
  342. #define ERR_DISKFULL      18
  343. #define ERR_UNRECOVERABLE 19
  344. #define ERR_NORECMANAGER  20
  345. #define ERR_KEYBUFLEN     21
  346. #define ERR_RECBUFLEN     22
  347. #define ERR_POSBLOCK      23
  348. #define ERR_PAGESIZE      24
  349. #define ERR_CREATEIO      25
  350. #define ERR_NUMKEYS       26
  351. #define ERR_KEYPOS        27
  352. #define ERR_RECLEN        28
  353. #define ERR_KEYLEN        29
  354. #define ERR_NOTBTRFILE    30
  355. #define ERR_EXTEND        31
  356. #define ERR_EXTENDIO      32
  357. #define ERR_EXTENDNAME    34
  358. #define ERR_DIRECTORY     35
  359. #define ERR_TRANSACTION   36
  360. #define ERR_BEGTRANS      37
  361. #define ERR_TRANSCONTROL  38
  362. #define ERR_ENDABORT      39
  363. #define ERR_TRANSACTMAX   40
  364. #define ERR_TRANSOPENCLOS 41
  365. #define ERR_ACCELACCESS   42
  366. #define ERR_INVALRECADD   43
  367. #define ERR_NULLKEYPATH   44
  368. #define ERR_KEYFLAGS      45
  369. #define ERR_ACCESSDENIED  46
  370. #define ERR_MAXOPENFILES  47
  371. #define ERR_ALTCOLSEQ     48
  372. #define ERR_KEYTYPE       49
  373. #define ERR_OWNERSET      50
  374. #define ERR_INVALIDOWNER  51
  375. #define ERR_WRITINGCAHCE  52
  376. #define ERR_INVINTERFACE  53
  377.  
  378. Page 8                                                                  BTRV Express
  379.                                                                                     
  380.  
  381. #define ERR_CONFLICT      80
  382. #define ERR_LOCKFULL      81
  383. #define ERR_LOSTPOSITION  82
  384. #define ERR_OUTSIDETRANS  83
  385. #define ERR_RECORDINUSE   84
  386. #define ERR_FILEINUSE     85
  387. #define ERR_FILEFULL      86
  388. #define ERR_HANDLEFULL    87
  389. #define ERR_MODE          88
  390. #define ERR_NAME          89
  391. #define ERR_DEVICEFULL    90
  392. #define ERR_SERVER        91
  393. #define ERR_TRANSFULL     92
  394. #define ERR_DEMO24        99
  395.  
  396.  
  397.  
  398. Constants used in calls to BFILEINFO
  399.  
  400. #define NUM_RECS 1
  401. #define REC_LEN  2
  402. #define PG_SIZE  3
  403. #define INDEXES  4
  404. #define FLAGS    5
  405. #define ALL      6
  406.  
  407.  
  408. File Definition Structures (used in BFILEINFO)
  409.  
  410. typedef struct {
  411.    int  key_pos;
  412.    int  key_len;
  413.    int  key_flags;
  414.    long num_keys;
  415.    unsigned char ext_key_type;
  416.    unsigned char null_value;
  417.    char reserved[4];
  418. } BTRSEGMENT;
  419.  
  420. typedef struct
  421.    {
  422.    int reclen;
  423.    int pgsize;
  424.    int numind;
  425.    long numrecs;
  426.    int fileflags;
  427.    char res[4];
  428.    BTRSEGMENT segment[24];
  429.    char altcolseq[264];
  430.    int buf_len;
  431. } STATBUF;
  432.  
  433. Page 9                                                                  BTRV Express
  434.                                                                                     
  435.  
  436. General Structures
  437.  
  438. struct BTR_FILES {
  439.        char *file_name;
  440.        char *pos_blk;
  441.        char *last_rec_buf;
  442.        int  rec_len;
  443.        int  last_index;
  444.        } btr_files[15];
  445.  
  446. typedef struct {
  447.    int  btr_major;
  448.    int  btr_minor;
  449.    char net;
  450.        int  lib_major;
  451.        int  lib_minor;
  452. } BTR_VERSION;
  453.  
  454.  
  455.  
  456. Function Prototypes
  457.  
  458. int  BADD(char *,char *) ..........................................ADD a record
  459. int  BCHANGEINDEX(char *,int) ......................Change current index Number
  460. int  BCLEAROWNER(char *) ......................................Clear File Owner
  461. int  BCLOSE(char *) .....................................CLOSE one or all files
  462. int  BCREATE(char *, STATBUF *) ..............................CREATE a new file
  463. int  BDELETE(char *) .....................................DELETE current record
  464. int  BFILEINFO(char *,int,void *) .........................Get File Information
  465. int  BGET(int,char *,int,char *,char *) .............................Get Record
  466. int  BGETDIRECT(char *,void *,char *) .................Get Record by Position #
  467. int  BGETDIRECTORY(int,char *) ...........................Get Current Directory
  468. int  BGETPOSITION(char *,void *) ..............Get Position # of Current Record
  469. int  BSETDIRECTORY(char *) ...............................Set Current Directory
  470. int  BSETOWNER(char *,char *,int)................................Set File Owner
  471. int  BSTART(void) ...........................................Initialize Library
  472. void BTR_ERROR(int, char *) .....................Display Error Message and Exit
  473. int  BTRANS(int) ...........................................Manage Transactions
  474. int  BTRV(int,char *,void *,int *,char *,int) ................BTRIEVE INTERFACE
  475. int  BUNLOCK(char *) ....................................Unlock Records in File
  476. int  BUPDATE(char *,void *) ..............................Update Current Record
  477. int  BXTR(int,char *,int,char *,char *) .................Central Calling Module
  478. int  BZAP(char *) ...................................Delete All Records in File
  479. int  GET_FILE_NUM(char *) .......................Get Index into BTR_FILES Array
  480. int  GET_ERR_MSG(int).......................Return Description of Btrieve Error
  481.  
  482.  
  483.  
  484.  
  485. The following pages describe each function individually.
  486. Page 10                                                                 BTRV Express
  487.                                                                                     
  488.  
  489. int BADD(char *filename, char *record_buf)
  490.  
  491. What it does:
  492.  
  493.        Use this function to add new records to your data files.
  494.  
  495.  
  496. Parameters:
  497.  
  498.        char *filename:  File name.
  499.  
  500.        char *record_buf:  Record to add.
  501.  
  502.  
  503. Returns:
  504.        
  505.        Status of Btrieve Call
  506.  
  507.           - or -
  508.  
  509.    Exits program if file not found
  510.  
  511.  
  512. Example:
  513.  
  514.        Add a new employee record to a file.
  515.  
  516.        struct
  517.           {
  518.           char Name[30];
  519.           char Address[40];
  520.           unsigned long Emp_Num;
  521.           } Employee;
  522.        int status;
  523.  
  524.        strcpy(Employee.Name,"Leonard Bernstein");
  525.        strcpy(Employee.Address,"Philharmonic Hall");
  526.        Employee.Number = 5768L;
  527.        status = BADD("EMPLOYEE.DAT",&Employee);
  528.        if (status == ERR_DUPLICATE) 
  529.           printf("That number already exists");
  530.  
  531. Notes:
  532.  
  533. BADD will return a status code under all circumstances except when the 
  534. requested file does not exist.  Your application must have code to decide what 
  535. to do in the event of an error.
  536.  
  537. Page 11                                                                 BTRV Express
  538.                                                                                     
  539.  
  540. int BCHANGEINDEX(char *filename, int index)
  541.  
  542. What it does:
  543.  
  544. Use this function to change the current index of a file without seeking another 
  545. record.  Btrieve will not normally let you search for a record using one index 
  546. and go to the next record using another index.  The function is called 
  547. automatically by BGET if you request a different index than the last one you 
  548. used.  Therefore, you will generally not need to use this function.
  549.  
  550.  
  551. Parameters:
  552.  
  553.        char *filename: File name.
  554.  
  555.        int index: New key number to use when stepping through file.
  556.  
  557.  
  558. Returns:
  559.  
  560.        0 if successful.
  561.        ERR_INVALKEYNUM (6) if key does not exist.
  562.  
  563.        Exits program if file not found.
  564.  
  565. Example:
  566.  
  567.        Search for an Employee by number (key 0) and then list the next three in 
  568.        alphabetical order (key 1).
  569.  
  570.        struct
  571.           {
  572.           char Name[30];
  573.           char Address[40];
  574.           unsigned long Emp_Num;
  575.           } Employee;
  576.        int status,i;
  577.        unsigned long Emp_Number;
  578.        
  579.        Emp_Number = 34215L;
  580.        status = BGET(B_GE,"EMPLOYEE.DAT",0,Employee,&Emp_Number);
  581.        status = BCHANGEINDEX("EMPLOYEE.DAT",1);
  582.        for (i=0 ; i<3 && status == 0; i++)
  583.           {
  584.           printf("%s\n",Employee.Name);
  585.           status = BGET(B_NEXT,"EMPLOYEE.DAT",1,Employee,keytemp);
  586.           }
  587.  
  588. Notes:
  589.  
  590. Remember that in the above example, the BCHANGEINDEX call is not really 
  591. needed.  The BGET NEXT call will automatically call BCHANGEINDEX if it detects 
  592. the change.
  593. Page 12                                                                 BTRV Express
  594.                                                                                     
  595.  
  596. int BCLEAROWNER(char *filename)
  597.  
  598. What it does:
  599.  
  600.        Clears ownership of a file.  Removes need to identify owner each time 
  601.        the file is opened.
  602.  
  603. Parameters:
  604.  
  605.        char *filename: Name of file to remove ownership.
  606.  
  607. Returns:
  608.  
  609.        0 if successful.       
  610.  
  611.        Exit to DOS if bad file name.
  612.  
  613. Example:
  614.  
  615.        status = BCLEAROWNER("EMPLOYEE.DAT");
  616.  
  617. Notes:
  618.  
  619.        The file must be properly opened with correct ownership before making 
  620.        this call.
  621.  
  622. Page 13                                                                 BTRV Express
  623.                                                                                     
  624.  
  625. int BCLOSE(char *filename)
  626.  
  627. What it does:
  628.  
  629.        If BCLOSE is called with a filename, then that file will be closed.  The 
  630.        position block will be deallocated and the entry in the 'btr_files' 
  631.        array will be deleted.
  632.  
  633.  
  634.        If BCLOSE is called with ALL_FILES (a macro defined as NULL), then a 
  635.        Btrieve RESET will occur, all files will be closed and the entire 
  636.        'btr_files' array will be cleared.
  637.  
  638.  
  639. Parameters:
  640.  
  641.        char *filename = Name of file to close or ALL_FILES.
  642.  
  643.  
  644. Returns:
  645.        
  646.        Btrieve Status code of the close.
  647.  
  648.  
  649. Example:
  650.  
  651.        Close all files before exiting your application.
  652.  
  653.        status = BCLOSE(ALL_FILES);
  654.  
  655.  
  656. Notes:
  657.  
  658.        None.
  659. Page 14                                                                 BTRV Express
  660.                                                                                     
  661.  
  662. int BCREATE(char *filename, STATBUF *statbuf)
  663.  
  664. What it does:
  665.  
  666.        BCREATE will create a new file based on your specifications.  The 
  667.        function can be used in a number of ways.  It is called by BZAP, a 
  668.        routine that deletes all records in a file.  BZAP performs a BFILEINFO 
  669.        on the file which loads its definition into 'global_statbuf'.  The 
  670.        status buffer is then passed to BCREATE along with the original filename 
  671.        to create a new blank file.
  672.        
  673.        Another use for BCREATE and BFILEINFO is to copy just the structure of a 
  674.        file.  Use BFILEINFO to load the 'global_statbuf' and call BCREATE with 
  675.        a new file name.
  676.        
  677.        The length of the file definition must be passed in STATBUF.buf_len.
  678.        
  679.        See the Btrieve manual for information on how to assemble your own 
  680.        status buffer to create new files.
  681.  
  682.  
  683. Parameters:
  684.  
  685.        char *filename: Name of file to create (path can be included).
  686.  
  687.        STATBUF *statbuf: Pointer to valid Btrieve status (file definition) 
  688.        buffer.
  689.        
  690.  
  691. Returns:
  692.  
  693.        Status of Btrieve operation.  You must decide what to do on error.
  694.  
  695.  
  696. Example:
  697.  
  698.        Create a temporary file with the same structure as your employee file.
  699.  
  700.  
  701.        int status;
  702.  
  703.        status = BFILEINFO("EMPLOYEE.DAT",ALL);
  704.        status = BCREATE("EMPTEMP.DAT",&global_statbuf);
  705.  
  706.  
  707. Notes: 
  708.  
  709.        None.
  710.  
  711. Page 15                                                                 BTRV Express
  712.                                                                                     
  713.  
  714. int BDELETE(char *filename)
  715.  
  716. What it does:
  717.  
  718.        Deletes the current record from the file.  After deletion, the file will 
  719.        be placed at the next record according to the current index.  If you 
  720.        have just deleted the highest record on the index, the file will point 
  721.        to the next highest record.
  722.        
  723.        If the global variable 'DEL_POSITION' is FALSE, no position will be 
  724.        established after the delete call.  Your application must set the file's 
  725.        position.
  726.  
  727.  
  728. Parameters:
  729.  
  730.        char *filename: Name of file.
  731.  
  732.  
  733. Returns:
  734.  
  735.        0 if successful.
  736.        ERR_EOF (9) if there are no more records in the file.
  737.  
  738.        Program will exit if the filename is invalid.
  739.  
  740.  
  741. Example:
  742.  
  743.        Delete all of the Robinsons from the Employee file.  Use global variable 
  744.        BSTATUS to determine error conditions.
  745.  
  746.  
  747.        struct
  748.           {
  749.           char Name[30];
  750.           char Address[40];
  751.           unsigned long Emp_Num;
  752.           } Employee;
  753.    
  754.        int status;
  755.  
  756.        BGET(B_GE,"EMPLOYEE.DAT",0,Employee,"Robinson");
  757.        while (BSTATUS == 0 && strncmp("Robinson",Employee.Name,8) == 0)
  758.           BDELETE("EMPLOYEE.DAT");
  759.  
  760.  
  761. Notes:
  762.  
  763.        Note that a BGET NEXT call is not needed to find the next employee.
  764.  
  765. Page 16                                                                 BTRV Express
  766.                                                                                     
  767.  
  768. int BFILEINFO(char *filename, int type, void *parm)
  769.  
  770. What it does:
  771.  
  772.        BFILEINFO will first get the file's position, call a Btrieve STAT 
  773.        operation, load the parameter to pass back, and restore the file's 
  774.        position with a BGETDIRECT.  The STAT loads the 'global_statbuf' with 
  775.        the file's information.  The 'type' parameter lets the routine choose 
  776.        which piece to send back.
  777.  
  778.  
  779. Parameters:
  780.  
  781.        char *filename: Name of file.
  782.  
  783.        int type: Type of information requested.
  784.  
  785.              Possible values are:
  786.              
  787.              NUM_RECS - number of records
  788.              REC_LEN  - record length
  789.              INDEXES  - number of indexes
  790.              PG_SIZE  - page size
  791.              FLAGS    - Btrieve file flags (See Btrieve documentation)
  792.              ALL      - Load global_statbuf 
  793.  
  794.        void *parm: Pointer to returned information.
  795.  
  796.           'parm' must point an integer if 'type' is REC_LEN, INDEXES, PG_SIZE, 
  797.           or FLAGS.
  798.           
  799.           'parm' must point to an unsigned long integer if 'type is NUM_RECS.
  800.           
  801.           If the type is 'ALL', you can pass NULL for the parameter 'parm'.  
  802.           The file's structure will be passed back in global_statbuf.  
  803.           Otherwise, you must pass a pointer to a STATBUF structure.
  804.           
  805.           
  806. Example:
  807.  
  808.        Find out how many Employees there are in the file.
  809.  
  810.        unsigned long NUM_EMPS;
  811.        
  812.        status = BFILEINFO("EMPLOYEE.DAT",NUM_RECS,&NUM_EMPS);
  813.        printf("There are %lu Employees Here",NUM_EMPS);
  814.  
  815. Returns:
  816.        
  817.        0 if successful.  Otherwise, it will return the status of the 
  818.        GETPOSITION call at the end of the routine.
  819.        
  820. Notes: 
  821.  
  822.        None.
  823. Page 17                                                                 BTRV Express
  824.                                                                                     
  825.  
  826. int BGET  (int get_type, char *filename, int index, char *rec_buf, 
  827.           char *key_buf)
  828.  
  829. What it does: 
  830.  
  831.        BGET is the main procedure used to access the records in your file.  
  832.        Tell it the file name, index, what kind of search, and where to put the 
  833.        answer to your query.
  834.        
  835.        Record Locking is accomplished by adding a locking constant to the 
  836.        get_type.  Locking constants are:
  837.        
  838.              B_LOCK_WAIT  : Record lock with waiting.
  839.        
  840.              B_LOCK_NOWAIT: Record lock without waiting.
  841.  
  842.  
  843. Parameters:
  844.  
  845.        int get_type: Type of search.
  846.  
  847.           Possible values:
  848.  
  849.              These values return entire records:
  850.  
  851.              B_EQ    - get equal to 
  852.              B_GT    - get greater than
  853.              B_GE    - get greater than or equal to
  854.              B_LT    - get less than
  855.              B_LE    - get less than or equal to
  856.              B_LOW   - get lowest
  857.              B_HIGH  - get highest
  858.              B_NEXT  - get next in order
  859.              B_PREV  - get previous in order
  860.  
  861.  
  862.              These values return keys only (see Btrieve manual for 
  863.              explanation):
  864.              
  865.              B_EQ_KEY    - get equal to 
  866.              B_GT_KEY    - get greater than
  867.              B_GE_KEY    - get greater than or equal to
  868.              B_LT_KEY    - get less than
  869.              B_LE_KEY    - get less than or equal to
  870.              B_LOW_KEY   - get lowest
  871.              B_HIGH_KEY  - get highest
  872.              B_NEXT_KEY  - get next in order
  873.              B_PREV_KEY  - get previous in order
  874.        
  875.        char *filename: File name.
  876.  
  877.        int index: Index number to use for search.  A value of -1 will cause the 
  878.        library to use the last known index number for the file.
  879.        
  880.        
  881. Page 18                                                                 BTRV Express
  882.                                                                                     
  883.  
  884.        char *rec_buf: Record buffer address.  Passing a NULL value here will 
  885.        tell the library to use the last known record buffer.
  886.        
  887.        char *key_buf: buffer of key to search for.  You can pass 'keytemp' or 
  888.        NULL in this parameter if you wish (both have the same effect).
  889.  
  890.  
  891. Returns:
  892.  
  893.        Status of Btrieve call.
  894.  
  895.        Program will exit if the file does not exist.
  896.  
  897.  
  898. Example:
  899.  
  900.        Print all of your employee's names.
  901.  
  902.        struct
  903.           {
  904.           char Name[30];
  905.           char Address[40];
  906.           unsigned long Emp_Num;
  907.           } Employee;
  908.        int status;
  909.  
  910.        status = BGET(B_LOW,"EMPLOYEE.DAT",0,&Employee,keytemp);
  911.        while (status == 0)
  912.           {
  913.           printf("%s\n",Employee.Name);
  914.           status = BGET(B_NEXT,"EMPLOYEE.DAT",0,&Employee,keytemp);
  915.           }
  916.  
  917.        
  918. Example call with wait lock:
  919.  
  920.        BGET(B_LOW+B_LOCK_WAIT,"EMPLOYEE.DAT",0,&Employee,keytemp);
  921.  
  922.        For a full example with record locking see BUPDATE().
  923.  
  924.        
  925. Notes:
  926.  
  927.        After every call to BGET, the 'keytemp' buffer holds the complete key 
  928.        value of the record just retrieved.  For instance, suppose that your 
  929.        employee file has a key consisting of Employee Number concatenated with 
  930.        the Employee Name.  A call to retrieve the record by just the employee 
  931.        number will load 'keytemp' with the full key (Number and Name).  You can 
  932.        use that value as needed, but remember that this buffer is subject to 
  933.        change during the next library call.
  934.        
  935.        If RETURN_KEY_BUFFER is set TRUE or if you have requested a key-only 
  936.        retrieval, make sure that you have enough room in your defined key 
  937.        buffer for the returned value.
  938.  
  939.  
  940. Page 19                                                                 BTRV Express
  941.                                                                                     
  942.  
  943. int BGETDIRECT(char *filename, void *position, char *rec_buf)
  944.  
  945.  
  946. What it does:
  947.  
  948.        Positions a file based on a 4-byte position number.
  949.  
  950.  
  951. Parameters:
  952.  
  953.        char *filename: File name.
  954.  
  955.        void *position: Pointer to 4-byte position buffer.
  956.  
  957.        char *rec_buf: Pointer to record buffer.  If rec_buf is NULL, then BXTR 
  958.        will use the last known record buffer location.
  959.        
  960.  
  961. Returns:
  962.  
  963.        Status of Btrieve call.
  964.  
  965.        Program will exit if file is not found.
  966.  
  967.  
  968. Example:
  969.  
  970.        Position the file based on an external index.
  971.  
  972.        struct {
  973.           char SSN[11];
  974.           unsigned long pos;
  975.           } EXT_KEY;
  976.  
  977.        struct
  978.           {
  979.           char Name[30];
  980.           char Address[40];
  981.           unsigned long Emp_Num;
  982.           } Employee;
  983.        int status;
  984.        unsigned long EMP_NUMBER;
  985.  
  986.        status = BGET(B_EQ,"EXTRAKEY.NDX",0,&EXT_KEY,&EMP_NUMBER);
  987.        if (status == 0)
  988.           status = BGETDIRECT("EMPLOYEE.DAT",&EXT_KEY.pos,&Employee);
  989.  
  990. Notes:
  991.  
  992.        None.
  993. Page 20                                                                 BTRV Express
  994.                                                                                     
  995.  
  996. int BGETDIRECTORY(int drive,char *path)
  997.  
  998. What it does:
  999.  
  1000.        Returns the current directory of the requested drive.
  1001.  
  1002. Parameters:
  1003.  
  1004.        int drive:  0 = use default drive
  1005.                    1 = Drive A
  1006.                    2 = Drive B
  1007.                    3 = Drive C   etc.
  1008.        
  1009.        char *path: buffer to receive directory.  This buffer must be at 
  1010.        least 64 bytes long.
  1011.  
  1012. Returns:
  1013.  
  1014.        STATUS of Btrieve call.
  1015.  
  1016. Example:
  1017.  
  1018.        Report directory of current drive.
  1019.  
  1020.        char path[64];
  1021.  
  1022.        status = BGETDIRECTORY(0,path);
  1023.        printf("%s",path);
  1024.  
  1025. Notes: 
  1026.  
  1027.        None.
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033. Page 21                                                                 BTRV Express
  1034.                                                                                     
  1035.  
  1036. int BGETPOSITION(char *filename,void *pos)
  1037.  
  1038.  
  1039. What it does:
  1040.  
  1041.        Gets the 4-byte Btrieve position of the record in the named file.  This 
  1042.        value is to be used at some later time by a BGETDIRECT call.
  1043.        
  1044.  
  1045. Parameters:
  1046.  
  1047.        char *filename: File name.
  1048.  
  1049.        void *pos: Pointer to 4-byte position buffer.
  1050.  
  1051.  
  1052. Returns:
  1053.  
  1054.        Status of Btrieve call.
  1055.  
  1056.        Program will exit if file is not found.
  1057.  
  1058.  
  1059. Example:
  1060.  
  1061.        long pos;
  1062.  
  1063.        status = BGETPOSITION("EMPLOYEE.DAT",&pos);
  1064.  
  1065.        See Btrieve documentation examples for use of this call.
  1066.  
  1067.  
  1068. Notes:
  1069.  
  1070.        None.
  1071.  
  1072. Page 22                                                                 BTRV Express
  1073.                                                                                     
  1074.  
  1075. int BSETDIRECTORY(char *path)
  1076.  
  1077. What it does:
  1078.  
  1079.        Sets the current directory on any drive.
  1080.  
  1081.        If the path name does not include a drive specification, the default 
  1082.        drive is assumed.
  1083.  
  1084. Parameters:
  1085.  
  1086.        char *path: Pathname to set.
  1087.  
  1088. Example:
  1089.  
  1090.        Change to the "\BTRIEVE" directory on the current drive.
  1091.  
  1092.        status = BSETDIRECTORY("\\BTRIEVE");
  1093.  
  1094. Returns:
  1095.  
  1096.        0 if successful.
  1097.  
  1098.        Exit to DOS if error occurs.
  1099.  
  1100. Notes: 
  1101.  
  1102.        This function works exactly like the DOS "CHDIR" command.
  1103.        
  1104.        -  If the first character of 'path' is not a backslash, the path is 
  1105.           appended to the current directory.
  1106.        
  1107.        -  If a drive specification is given in 'path', it sets the current 
  1108.           directory on that drive but does not effect your default drive 
  1109.           status.  For example if you are currently on drive C and call this 
  1110.           function with path = "D:\APPLIC", your default drive will still be 
  1111.           C.  Your application must specifically change drives to access D.
  1112.        
  1113.  
  1114. Page 23                                                                 BTRV Express
  1115.                                                                                     
  1116.  
  1117. int BSETOWNER(char *filename,char *owner,int mode)
  1118.  
  1119. What it does:
  1120.  
  1121.        Establishes ownership of a Btrieve file.  Once a file has been assigned 
  1122.        an owner, the owner's name must be passed in the record buffer when the 
  1123.        file is opened.  If the name is not present, the file cannot be used.
  1124.        
  1125. Parameters:
  1126.  
  1127.        char *filename: Name of file.
  1128.  
  1129.        char *owner: Owner name.  ASCIIZ string of up to eight characters.
  1130.  
  1131.        int mode:  0 - Requires owner ID for any access; no data encryption
  1132.               1 - Permit read-only access without owner ID; no data
  1133.                   encryption
  1134.                   2 - Requires owner ID for any access; data encryption
  1135.               3 - Permit read-only access without owner ID; data
  1136.                   encryption
  1137.  
  1138. Example:
  1139.        
  1140.        Set an owner for a file, permit read-only access with no ID, do not 
  1141.        encrypt data.
  1142.        
  1143.        status = BSETOWNER("employee.dat","TWIT",0);
  1144.        
  1145. Returns:
  1146.        
  1147.        0 if successful.
  1148.  
  1149.        Exit to DOS if error occurs.
  1150.  
  1151. Notes:
  1152.        
  1153.        Once ownership has been set, the owner ID must be present in the record 
  1154.        buffer whenever the file is subsequently opened.
  1155.        
  1156.        It is suggested that for those files with ownership, you use a UNION 
  1157.        structure with your defined record buffer to make life easier.  See the 
  1158.        example on the following page.
  1159.  
  1160.        union {
  1161.           struct {
  1162.              char EMP_NUM[5];
  1163.              char EMP_NAME[20];
  1164.              } record
  1165.           char owner[9];
  1166.        } EMP_BUF;
  1167.        
  1168.        strcpy(EMP_BUF.owner,"TWIT");
  1169.        BGET(B_LOW,"employee.dat",0,&EMP_BUF.record,keytemp);
  1170.        
  1171. Page 24                                                                 BTRV Express
  1172.                                                                                     
  1173.  
  1174.        After the first call to the file, assuming it is successful, you do not 
  1175.        need the owner ID in the record buffer.
  1176.        
  1177.        If you forget the owner ID, there is no way to recall it from the file.
  1178.  
  1179. Page 25                                                                 BTRV Express
  1180.                                                                                     
  1181.  
  1182. int BSTART()
  1183.  
  1184. What it does:
  1185.  
  1186.        Makes sure that Btrieve is loaded in memory and locates file which 
  1187.        contains the error messages.
  1188.        
  1189.        The first thing this module does is try and load the version of Btrieve 
  1190.        into the the global variable, BTR_VERSION.  This variable's structure 
  1191.        is:
  1192.        
  1193.                     struct {
  1194.                       int btr_major;
  1195.                       int btr_minor;
  1196.                       char net;
  1197.                       int  lib_major;
  1198.                       int  lib_minor;
  1199.                     } BTR_VERSION;
  1200.        
  1201.        If this call fails, then Btrieve is not loaded in memory and the library 
  1202.        will print an appropriate message and exit to DOS.  
  1203.        
  1204.        If the call is successful, then the version of Btrieve as well as the 
  1205.        version number of this library are available to your application.
  1206.        
  1207.        The second thing this module does is search for the file BTRERROR.DAT.  
  1208.        If this file is not in the current directory or current DOS search path, 
  1209.        then the library cannot print its standard error messages.  A predefined 
  1210.        error message will print and the library will exit to DOS.  
  1211.        
  1212.        If you do not plan to use the predefined error messages and do not want 
  1213.        the library to search for BTRERROR.DAT, set CATCH_ERROR to FALSE before 
  1214.        calling BSTART().
  1215.        
  1216.        If the version is loaded correctly and the error file is found, then 
  1217.        control is returned to your application.
  1218.  
  1219. Returns:
  1220.        
  1221.        0 if successful.
  1222.        Exits to DOS if error occurs.
  1223.  
  1224. Example:
  1225.  
  1226.        status = BSTART();
  1227.  
  1228. Notes:
  1229.  
  1230.        None.
  1231.  
  1232. Page 26                                                                 BTRV Express
  1233.                                                                                     
  1234.  
  1235. void BTR_ERROR(int op, char *message)
  1236.  
  1237.  
  1238. What it does:
  1239.  
  1240.        Go to the bottom of the screen, display the operation code, status of 
  1241.        last Btrieve call (held in global variable BSTATUS), and an error 
  1242.        message before exiting back to DOS.  This routine is called when the 
  1243.        library catches a critical error.
  1244.        
  1245.        The error message can be supplied in one of two ways.  If BSTATUS is not 
  1246.        equal to zero, this function will search for BSTATUS in a special file 
  1247.        called BTRERROR.DAT.  The message which to corresponds to that error 
  1248.        number will be displayed.  If you wish to supply your own error message, 
  1249.        set BSTATUS to 0 and pass the message instead of a filename for the 
  1250.        second parameter.
  1251.        
  1252.        After the message is displayed, a Btrieve RESET function is called 
  1253.        (unless the error number is 20) and the program will exit out to DOS.
  1254.  
  1255. Parameters:
  1256.  
  1257.        int op: Operation being performed when error occurred.
  1258.  
  1259.        char *message: Pointer to error message.
  1260.  
  1261. Returns:
  1262.        
  1263.        No return code. Program exits to DOS.  
  1264.  
  1265. Example:
  1266.  
  1267.        Check for duplicate employee numbers when entering a record.  Exit to 
  1268.        DOS if a duplicate is found.  Use global variable BSTATUS to check for 
  1269.        error.
  1270.  
  1271.        int status;
  1272.        struct
  1273.           {
  1274.           char Name[30];
  1275.           char Address[40];
  1276.           unsigned long Emp_Num;
  1277.           } Employee;
  1278.    
  1279.        strcpy(Employee.Name,"James Taylor");
  1280.        strcpy(Employee.Address,"111 Fire and Rain Lane");
  1281.        Employee.Emp_Num = 5555L;
  1282.        BADD("EMPLOYEE.DAT",&Employee);
  1283.        if (BSTATUS == ERR_DUPLICATE)
  1284.           BTR_ERROR(B_ADD,"EMPLOYEE.DAT");
  1285.  
  1286. Notes:
  1287.  
  1288.        None.
  1289. Page 27                                                                 BTRV Express
  1290.                                                                                     
  1291.  
  1292. int BTRANS(int transtype)
  1293.  
  1294.  
  1295. What it does:
  1296.  
  1297.        Calls Btrieve and tells it to Begin, End or Abort transaction.  Also 
  1298.        sets global variable TRANS_IN_PROGRESS to TRUE or FALSE.
  1299.  
  1300.  
  1301. Parameters:
  1302.  
  1303.        int transtype:
  1304.  
  1305.           B_BEGTRANS   - Begin Transaction ; TRANS_IN_PROGRESS = TRUE
  1306.           B_ENDTRANS   - End Transaction   ; TRANS_IN_PROGRESS = FALSE
  1307.           B_ABORTTRANS - Abort Transaction ; TRANS_IN_PROGRESS = FALSE
  1308.  
  1309.  
  1310. Returns:
  1311.  
  1312.        0 if successful.  
  1313.        
  1314.        Program will exit to DOS if an incorrect parameter is passed or the 
  1315.        Btrieve call produces an error.
  1316.        
  1317.  
  1318. Example:
  1319.  
  1320.        int status;
  1321.  
  1322.        status = BTRANS(B_BEGTRANS);
  1323.           .
  1324.           .
  1325.           .
  1326.           calls adding or updating records;
  1327.           .
  1328.           .
  1329.        if (status != 0)
  1330.           status = BTRANS(B_ABORTTRANS);
  1331.        else
  1332.           status = BTRANS(B_ENDTRANS);
  1333.  
  1334.  
  1335. Notes:
  1336.  
  1337.        Beginning a transaction involves no writing to files.  Ending a 
  1338.        transaction gives the user no control over file writes.  Because of 
  1339.        this, the call to Btrieve is made directly from this routine and not 
  1340.        through BXTR.
  1341.  
  1342.  
  1343. Page 28                                                                 BTRV Express
  1344.                                                                                     
  1345.  
  1346. int BTRV  (int op, char *position_block, char *record_buffer, 
  1347.           int *record_length, char *key_buffer, int index)
  1348.           
  1349.  
  1350. What it does:
  1351.  
  1352.        Standard interface call to Btrieve.
  1353.  
  1354. Notes:
  1355.  
  1356.        See Btrieve Manual.
  1357.  
  1358. Page 29                                                                 BTRV Express
  1359.                                                                                     
  1360.  
  1361. int BUNLOCK(char *filename)
  1362.  
  1363. What it does:
  1364.  
  1365.        Unlocks all records in the named file.
  1366.  
  1367.  
  1368. Parameters:
  1369.  
  1370.        char *filename: Name of file to unlock.
  1371.  
  1372.  
  1373. Returns:
  1374.        
  1375.        0 if successful.
  1376.  
  1377.        Exit to DOS if error occurs.
  1378.  
  1379.  
  1380. Example:
  1381.  
  1382.        status = BUNLOCK("employee.dat");
  1383.  
  1384.  
  1385. Notes:
  1386.  
  1387.        None.
  1388.  
  1389. Page 30                                                                 BTRV Express
  1390.                                                                                     
  1391.  
  1392. int BUPDATE(char *filename, void *rec_buf)
  1393.  
  1394.  
  1395. What it does:
  1396.  
  1397.        Updates the current record with the information in rec_buf.  Because an 
  1398.        update sometimes does not position the file correctly, the library gets 
  1399.        the 4-byte position number of the current record before the call and 
  1400.        does a BGETDIRECT after the call.  This ensures that the file is 
  1401.        correctly positioned.
  1402.  
  1403.  
  1404. Parameters:
  1405.  
  1406.        char *filename: File name.
  1407.  
  1408.        char *rec_buf: Pointer to record buffer.
  1409.  
  1410.  
  1411. Returns:
  1412.  
  1413.        If the UPDATE call to Btrieve fails, the return code is the Btrieve 
  1414.        error code.  Otherwise, the return code is the result of the final 
  1415.        BGETPOSITION call.
  1416.  
  1417.        Program will exit to DOS if file is not found.
  1418.  
  1419.  
  1420. Example:
  1421.  
  1422.        Change an employee's address.  Lock the record while editing.
  1423.  
  1424.        struct
  1425.           {
  1426.           char Name[30];  char Address[40];  unsigned long Emp_Num;
  1427.           } Employee;
  1428.    
  1429.        BGET(B_EQ+B_LOCK_WAIT,"EMPLOYEE.DAT",0,&Employee,"Willard, Fred");
  1430.        if (BSTATUS == 0)
  1431.           {
  1432.           strcpy(Employee.Address,"10 Madison Ave");
  1433.           BUPDATE("EMPLOYEE.DAT",&Employee);
  1434.           BUNLOCK("EMPLOYEE.DAT");
  1435.           }
  1436.  
  1437. Notes: 
  1438.  
  1439.        Since all library calls position the file at some record, the only times 
  1440.        an update should fail are: 
  1441.        
  1442.           - The file name is invalid.
  1443.           - There are no records in the file.
  1444.           - There is some hardware error.
  1445. Page 31                                                                 BTRV Express
  1446.                                                                                     
  1447.  
  1448. int BXTR  (int op, char *filename, int index, char *record_buffer, 
  1449.           char *key_buffer)
  1450.  
  1451.  
  1452. What it does:
  1453.  
  1454.        This is the module through which the library make almost all calls to 
  1455.        Btrieve.  It manages the 'btr_files' array, allocates position blocks, 
  1456.        makes sure that there are proper buffers for all activities, and catches 
  1457.        some fundamental program errors such as bad file names or too many open 
  1458.        files.
  1459.        
  1460.        Some of the parameters can be supplied through defaults stored in the 
  1461.        btr_files array.  If the index parameter is passed as -1, BXTR will use 
  1462.        the last known index number.  The 'rec_buf' pointer has a similar 
  1463.        default mode.  If the pointer is NULL, BXTR will use the last_rec_buf 
  1464.        (stored in the 'btr_files' array) for that file.  If the key_buf 
  1465.        parameter is NULL, keytemp is used.
  1466.        
  1467.        Under some conditions, there is no support information for the file.  
  1468.        For instance, if the first call to a file is through BFILEINFO, then no 
  1469.        previous record buffer exists.  In cases like this, a temporary record 
  1470.        buffer will be allocated, used for the call, and freed afterward.  In 
  1471.        other cases, a dummy position block is allocated as well.
  1472.        
  1473.        BXTR will also manage the shuffling around of the 4-byte position buffer 
  1474.        during BGETPOSITION and BGETDIRECT calls.  This ensures that a 
  1475.        BGETPOSITION call works correctly but the first four characters of the 
  1476.        record buffer are properly restored afterward.
  1477.        
  1478.        You should not have to call this function directly for normal 
  1479.        processing.  However, if you are brave enough to modify source code, you 
  1480.        can put your own routines in here.
  1481.        
  1482.        One idea for added functionality would be to use some kind of signal 
  1483.        detecting code just before the actual BTRV call.   The code could see if 
  1484.        a system administrator would like all users to log off of the network.  
  1485.        The routine would detect the signal, log the users off and change the 
  1486.        default drive to the local hard disk.  This saves you the hassle of 
  1487.        writing code for special logoff procedures or error detecting procedures 
  1488.        every time you request a record.  Because virtually all I/O is directed 
  1489.        through this module, you can just write the code once.
  1490.  
  1491. Parameters:
  1492.  
  1493.        int op: Btrieve Operation number.  There are macro definitions for these 
  1494.        numbers. See BTRVDEFS.H.
  1495.  
  1496.        char *filename: File name.
  1497.  
  1498.        int index: Index number to use for record retrieval.  If index = -1, 
  1499.        then the library will use the last known index number which is stored in 
  1500.        the BTR_FILES array.  If there is no last known index, the library will 
  1501.        supply a value of 0.
  1502.  
  1503. Page 32                                                                 BTRV Express
  1504.                                                                                     
  1505.  
  1506.        char *record_buffer: Pointer to record buffer.  If this pointer is NULL, 
  1507.        the library will use the last known record buffer pointer.  Under 
  1508.        special circumstances when there is no last known pointer, a temporary 
  1509.        buffer will be allocated for the call and freed before returning.
  1510.        
  1511.        char *key_buffer: Pointer to key buffer.  If the call is for a record 
  1512.        retrieval, the key buffer is unaltered by the call.  The key of the 
  1513.        returned record is returned in the global buffer 'keytemp'.
  1514.        
  1515.        If the call is a KEY operation (i.e., GET KEY), the key value is 
  1516.        returned in the buffer that is passed.
  1517.        
  1518.        If key_buffer is passed as NULL, the library will supply the pointer to 
  1519.        'keytemp' to the Btrieve call.
  1520.  
  1521.  
  1522. Example:
  1523.        
  1524.        This function is called by almost every module in the library.  Examine 
  1525.        the source code for examples of its usage.
  1526.  
  1527. Notes:
  1528.  
  1529.        None.
  1530.  
  1531. Page 33                                                                 BTRV Express
  1532.                                                                                     
  1533.  
  1534. int BZAP(char *filename)
  1535.  
  1536.  
  1537. What it does:   
  1538.  
  1539.        Deletes all records in a file.  Whereas the Btrieve delete function does 
  1540.        not reclaim the space used by a record, this function will reclaim it 
  1541.        all.  It creates an empty copy of the file using the same filename.
  1542.  
  1543.  
  1544. Parameters:
  1545.  
  1546.        char *filename: Name of file to zap.
  1547.  
  1548.  
  1549. Returns:
  1550.  
  1551.        Status of BCREATE call.
  1552.  
  1553.  
  1554. Example:
  1555.  
  1556.        status = BZAP("EMPLOYEE.DAT");
  1557.  
  1558.  
  1559. Notes:
  1560.  
  1561.        The function uses 'global_statbuf' to hold the file's definition.
  1562.  
  1563.  
  1564. Page 34                                                                 BTRV Express
  1565.                                                                                     
  1566.  
  1567. int GET_ERR_MSG(int errnum)
  1568.  
  1569. What it does:
  1570.  
  1571.        Returns a 40-character description of a Btrieve error code through the 
  1572.        global variable 'errmsg'.
  1573.  
  1574. Parameters:
  1575.  
  1576.        int errnum:  The status of the last library function call.
  1577.  
  1578.    global variable 'errmsg':
  1579.  
  1580.        struct ERROR_MSG {
  1581.           int errnum;
  1582.           char descrip[40];
  1583.           } errmsg;
  1584.  
  1585. Returns:
  1586.  
  1587.        If the error code is found in BTRERROR.DAT, the function returns 0 and 
  1588.        places the message and error number in global variable 'errmsg'.  
  1589.        Otherwise, returns the status of the record search.
  1590.  
  1591. Example:
  1592.  
  1593.        An error occurs while adding a record.  Print the error message.
  1594.        
  1595.        
  1596.        extern ERROR_MSG errmsg;
  1597.        
  1598.        main()
  1599.        {
  1600.           int status;
  1601.           char record[100];
  1602.           .
  1603.           .
  1604.           .
  1605.           status = BADD("employee.dat",&record);
  1606.           if (status != 0)
  1607.              {
  1608.              GET_ERR_MSG(status);
  1609.              printf("%.40s\n",errmsg.descrip);
  1610.              }
  1611.           .
  1612.           .
  1613.           .
  1614.        }
  1615.  
  1616. Notes:
  1617.        
  1618.        If you set CATCH_ERROR to FALSE before running BSTART(), then it is 
  1619.        possible that the file BTRERROR.DAT is unavailable.
  1620.  
  1621.  
  1622. Page 35                                                                 BTRV Express
  1623.                                                                                     
  1624.  
  1625. int GET_FILE_NUM(char *filename)
  1626.  
  1627.  
  1628. What it does:
  1629.  
  1630.        Returns the index into the 'btr_files' array of the file.
  1631.  
  1632.  
  1633. Parameters:
  1634.  
  1635.        char *filename: File name.
  1636.  
  1637. Returns:
  1638.  
  1639.        Number between 0 and MAX_BTR_FILES if successful or -1 if file is not 
  1640.        currently open.
  1641.  
  1642.  
  1643. Example:
  1644.  
  1645.        Find out if the last Employee was accessed by Name (index 0) or Number 
  1646.        (index 1).
  1647.  
  1648.  
  1649.        int status,fno;
  1650.        
  1651.        fno = GET_FILE_NUM("EMPLOYEE.DAT");
  1652.        if (fno != -1)
  1653.           if (btr_files[fno].last_index == 0)
  1654.              printf("Last access was by number");
  1655.           else
  1656.              printf("Last access was by name");
  1657.  
  1658.  
  1659. Notes:
  1660.  
  1661.        You will probably never have to call this function directly.  It is used 
  1662.        mostly by BXTR to attach position blocks and relevant information to the 
  1663.        file name that has been passed to a function.
  1664.  
  1665.  
  1666. Page 36                                                                 BTRV Express
  1667.                                                                                     
  1668.  
  1669. Btrieve Error Codes
  1670.  
  1671. These are the possible values that are returned from library function calls to 
  1672. Btrieve through BSTATUS.  For more information about each error code, see your 
  1673. Btrieve manual.
  1674.  
  1675.  1  INVALID OPERATION
  1676.  2  I/O ERROR (IS THIS A BTRIEVE FILE?)
  1677.  3  FILE NOT OPENED
  1678.  4  KEY NOT FOUND
  1679.  5  DUPLICATES ERROR
  1680.  6  INVALID KEY NUMBER
  1681.  7  DIFFERENT KEY NUMBER
  1682.  8  INVALID POSITIONING
  1683.  9  END OF FILE
  1684. 10  MODIFIABLE ERROR
  1685. 11  INVALID FILE NAME
  1686. 12  FILE NOT FOUND
  1687. 13  CANNOT FIND EXTENSION FILE
  1688. 14  PRE-OPEN ERROR
  1689. 15  PRE-IMAGE ERROR
  1690. 16  EXPANSION ERROR
  1691. 17  CLOSE ERROR
  1692. 18  DISK FULL
  1693. 19  UNRECOVERABLE ERROR
  1694. 20  RECORD MANAGER NOT ACTIVE
  1695. 21  KEY BUFFER NOT LONG ENOUGH
  1696. 22  RECORD BUFFER NOT LONG ENOUGH
  1697. 23  POSITION BLOCK NOT 128 BYTES
  1698. 24  PAGE SIZE ERROR
  1699. 25  CREATE I/O ERROR
  1700. 26  NUMBER OF KEYS
  1701. 27  KEY POSITION GREATER THAN RECORD LENGTH
  1702. 28  RECORD TOO LARGE FOR PAGE SIZE
  1703. 29  KEY LENGTH ERROR
  1704. 30  NOT VALID BTRIEVE FILE
  1705. 31  FILE ALREADY EXTENDED
  1706. 32  EXTEND I/O ERROR
  1707. 34  EXTEND NAME ERROR
  1708. 35  DIRECTORY ERROR
  1709. 36  TRANSACTION ERROR: USE /T WHEN LOADING
  1710. 37  OTHER TRANSACTION ALREADY ACTIVE
  1711. 38  TRANSACTION CONTROL FILE ERROR
  1712. 39  END/ABORT TRANSACTION ERROR
  1713. 40  TRANSACTION MAX FILES (MUST BE <12)
  1714. 41  OPEN/CLOSE DURING TRANSACTION
  1715. 42  INCOMPLETE ACCELERATED ACCESS
  1716. 43  INVALID DATA RECORD ADDRESS
  1717. 44  NULL KEY PATH
  1718. 45  INCONSISTENT KEY FLAGS
  1719. 46  ACCESS DENIED
  1720. 47  MAX OPEN BTRIEVE FILES (USE LARGER /M)
  1721. 48  INVALID ALTERNATE SEQUENCE DEFINITION
  1722. 49  KEY TYPE ERROR
  1723.  
  1724. Page 37                                                                 BTRV Express
  1725.                                                                                     
  1726.  
  1727. 50  OWNER ALREADY SET
  1728. 51  INVALID OWNER
  1729. 52  ERROR WRITING CACHE
  1730. 53  INVALID INTERFACE (UPGRADE YOUR BTRIEVE)
  1731. 80  CONFLICT
  1732. 81  LOCK FULL
  1733. 82  LOST POSITION
  1734. 83  READ OUTSIDE TRANSACTION
  1735. 84  RECORD IN USE
  1736. 85  FILE IN USE
  1737. 86  FILE TABLE FULL (USE LARGER /F)
  1738. 87  HANDLE FULL
  1739. 88  MODE ERROR
  1740. 89  NAME ERROR
  1741. 90  REDIRECTION TABLE FULL
  1742. 91  SERVER ERROR
  1743. 92  TRANSACTION FULL
  1744. 99  DEMO VERSION MUST USE <=24 RECORDS
  1745.  
  1746. Page 38                                                                 BTRV Express
  1747.                                                                                     
  1748.  
  1749. General Notes
  1750.  
  1751. 1)     The maximum number of open files is set in the BTRVEXP.C source code 
  1752.        file.  When you receive the library, this maximum number of files is 
  1753.        10.  To change that, you must set the definition for MAX_OPEN_FILES to 
  1754.        another number and recompile the library.
  1755.  
  1756. 2)     If you do change the source code for BTRVEXP.C, be sure to use the batch 
  1757.        file BOBJS.BAT to recompile for all four memory models.
  1758.  
  1759.  
  1760.  
  1761. Sample Programs
  1762.  
  1763. As an example of how to use the library functions, a set of practice files has 
  1764. been included on your disk.  The text file "AREACODE.TXT" contains a list of 
  1765. the telephone area codes for the fifty states. 
  1766.  
  1767. The next section of the manual describes how to use the BTRBUILD utility 
  1768. program to create Btrieve data files.  Follow the tutorial to create the file 
  1769. "AREACODE.DAT".  You can then use the programs "ALOAD.EXE" and "AREPORT.EXE" to 
  1770. load the data file and report on its contents.  The source code for the two 
  1771. ".EXE" files has been supplied on your disk.
  1772.  
  1773. A third file, "ACREATE.C" has been supplied to demonstrate the use of the 
  1774. BCREATE command.  To run that program, you must have the alternate collating 
  1775. sequence file "UPPER.ALT" in the current directory or DOS search path.
  1776.  
  1777. Other files provided show ways to access the records.  "AFIND.C" can be 
  1778. compiled to a program that will search the file for a given area code and 
  1779. return its state.  "ASTATE.C" will create a program that asks for a state 
  1780. abbreviation and returns all of the area codes in that state.
  1781.  
  1782. These source code samples should present a good picture of how the function 
  1783. calls interact.
  1784.  
  1785.  
  1786. Suggestions or Problems
  1787.  
  1788. If you have suggestions, comments or problems, you may contact:
  1789.  
  1790.           Srebnick Micro Consulting
  1791.           6 Kelly Road
  1792.           Hamden, Connecticut 06518
  1793.           (203) 248-6559
  1794.  
  1795. If you have a modem and access to Compuserve, you can leave messages at CIS 
  1796. ID#: 74017,3276.  
  1797.  
  1798.          ----------------end-of-author's-documentation---------------
  1799.  
  1800.                         Software Library Information:
  1801.  
  1802.                    This disk copy provided as a service of
  1803.  
  1804.                         The Public (Software) Library
  1805.  
  1806.          We are not the authors of this program, nor are we associated
  1807.          with the author in any way other than as a distributor of the
  1808.          program in accordance with the author's terms of distribution.
  1809.  
  1810.          Please direct shareware payments and specific questions about
  1811.          this program to the author of the program, whose name appears
  1812.          elsewhere in  this documentation. If you have trouble getting
  1813.          in touch with the author,  we will do whatever we can to help
  1814.          you with your questions. All programs have been tested and do
  1815.          run.  To report problems,  please use the form that is in the
  1816.          file PROBLEM.DOC on many of our disks or in other written for-
  1817.          mat with screen printouts, if possible.  The P(s)L cannot de-
  1818.          bug programs over the telephone.
  1819.  
  1820.          Disks in the P(s)L are updated monthly, so if you did not get
  1821.          this disk  directly from the P(s)L,  you should be aware that
  1822.          the files in this set may no  longer be the current versions.
  1823.  
  1824.          For a copy of the latest monthly software library newsletter
  1825.          and a list of the 1,900+ disks in the library, call or write
  1826.  
  1827.                         The Public (Software) Library
  1828.                               P.O.Box 35705 - F
  1829.                            Houston, TX 77235-5705
  1830.                                (713) 665-7017
  1831.  
  1832.